﻿Public Class dsGhiBan
    Dim ctx As New QLDBDataContext
    Private _phut As Integer
    Private _tenCT As String
    Private _tenCLB As String
    Private _matran As Integer
    Public Sub New()
        _phut = 0
        _tenCT = ""
        _tenCLB = ""
        _matran = -1
    End Sub

    Public Property Phut() As Integer
        Get
            Return _phut
        End Get
        Set(value As Integer)
            _phut = value
        End Set
    End Property

    Public Property TenCT() As String
        Get
            Return _tenCT
        End Get
        Set(value As String)
            _tenCT = value
        End Set
    End Property

    Public Property TenCLB() As String
        Get
            Return _tenCLB
        End Get
        Set(value As String)
            _tenCLB = value
        End Set
    End Property
    Public Property MaTran As Integer
        Get
            Return _matran
        End Get
        Set(value As Integer)
            _matran = value
        End Set
    End Property

    Private Function LayTenCT(ByVal Ma As Integer) As String
        Dim v = ctx.CAUTHUs.Single(Function(p) p.MaCT = Ma)
        Return v.HoTen
    End Function

    Private Function LayTenCLB(ByVal Ma As Integer) As String
        Dim v = ctx.CAULACBOs.Single(Function(p) p.MaCLB = Ma)
        Return v.TenCLB
    End Function

    Public Function LayDanhSachGB() As IList
        Dim v = From q In ctx.DANHSACHGHIBANs
                Select New dsGhiBan With {.Phut = q.ThoiDiem, .TenCT = LayTenCT(q.MaCT), .TenCLB = LayTenCLB(q.MaCLB), .MaTran = q.MaTran}

        Return v.ToList()

    End Function
End Class
